<template>
	<view>
		用户注册

		<image :src="kaptchaSrc" mode="aspectFit" @click="getKaptchaImg" class="kaptcha"></image>


		<navigator url="../login/login">已有账号?去登录</navigator>
	</view>
</template>

<script>
	import $api from '../../api/api'

	export default {
		computed: {
			passwordType: function() {
				return this.showPassword ? "text" : "password"
			},
			kaptchaSrc() {
				return "data:image/jpeg;base64," + this.kaptchaImgData
			}
		},
		data() {
			return {
				kaptchaImgData: "",
			}
		},
		methods: {
			getKaptchaImg() {
				$api.test.getKaptcha().then(base64 => {
					// console.log(res);
					// 得到的是图片的 base64数据,通过计算属性拼接渲染到img 
					this.kaptchaImgData = base64
				})

			}
		},
		onReady() {
			//onReady 为form 设置校验规则
			// this.$refs.loginform.setRules(this.rules)
			this.getKaptchaImg()
		},
	}
</script>

<style>
	.kaptcha {
		height: 30px;
	}
</style>